<?php

namespace Xrfg\Api\Consume\Models;

trait ConsumeAccountLogHelper
{
    public $availableChange;

    public $disabledChange;

    public $freezeChange;

    public static function boot()
    {
        parent::boot();

        static::updating(function ($model) {
            ++$model->version;
        });

        bcscale(8);
    }

    public function availableIncrement($number)
    {
        $this->available = bcadd($this->available, $number);
        $this->availableChange = +$number;
    }

    public function availableDecrement($number)
    {
        $this->available = bcsub($this->available, $number);
        $this->availableChange = -$number;
    }

    public function disabledIncrement($number)
    {
        $this->disabled = bcadd($this->disabled, $number);
        $this->disabledChange = +$number;
    }

    public function disabledDecrement($number)
    {
        $this->disabled = bcsub($this->disabled, $number);
        $this->disabledChange = -$number;
    }

    public function freezeIncrement($number)
    {
        $this->freeze = bcadd($this->freeze, $number);
        $this->freezeChange = +$number;
    }

    public function freezeDecrement($number)
    {
        $this->freeze = bcsub($this->freeze, $number);
        $this->freezeChange = -$number;
    }
}
